//
//  TextFiledViewController.m
//  muce
//
//  Created by  yunshao on 2018/3/23.
//  Copyright © 2018年  yunshao. All rights reserved.
//

#import "TextFiledViewController.h"
#import "pch.h"

@interface TextFiledViewController ()
@property(nonatomic,strong)UIView * backView;
@property(nonatomic,strong)UIButton * backButton;               //返回按钮
@property(nonatomic,strong)UILabel * titleLable;                //标题
@property(nonatomic,strong)UITextField * textFiled;             //输入框
@property (nonatomic,strong)UIButton * sendBtn;                 //确定按钮。

@end

@implementation TextFiledViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addMianView];
}

-(void)addMianView{
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DSDevice_W, DSFixedPX(110))];
    _backView.backgroundColor = DSColorWithHex(0x3279ca);
    _backView.userInteractionEnabled = YES;
    [self.view addSubview:_backView];
    
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _backButton.frame = CGRectMake(DSFixedPX(20), DSFixedPX(40), DSFixedPX(40), DSFixedPX(40));
    [_backButton setImage:[UIImage imageNamed:@"title_back"] forState:UIControlStateNormal];
    [_backButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_backView addSubview:_backButton];
    _titleLable = [[UILabel alloc]initWithFrame:CGRectMake(DSFixedPX(40), DSFixedPX(40), DSDevice_W - DSFixedPX(80), DSFixedPX(50))];
    _titleLable.text = @"评价内容";
    _titleLable.textAlignment = NSTextAlignmentCenter;
    _titleLable.font = DSFontSize(16);
    _titleLable.textColor = DSColorWithHex(0xffffff);
    [_backView addSubview:_titleLable];
    
    
    _textFiled = [[UITextField alloc]initWithFrame:CGRectMake(DSFixedPX(10), DSFixedPX(120), DSDevice_W, DSFixedPX(50))];
    _textFiled.placeholder = @"请输入评价内容";
    [self.view addSubview:self.textFiled];
    
    _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _sendBtn.frame = CGRectMake(DSFixedPX(50), DSDevice_H /2.0f, DSDevice_W - DSFixedPX(100), DSFixedPX(80));
    [_sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    _sendBtn.backgroundColor = DSColorWithHex(0x3279ca);
    _sendBtn.layer.masksToBounds = YES;
    _sendBtn.layer.cornerRadius = 5.0f;
    [_sendBtn addTarget:self action:@selector(sendBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_sendBtn];
}
-(void)sendBtnClicked{
    self.contentString = [NSString stringWithFormat:@"%@",_textFiled.text];
    [self sendHttp];
}

-(void)sendHttp{
    //预览用户
    if ([[LPCommonTool readIdengit] integerValue] == 1) {
        
       // [SVProgressHUD showSuccessWithStatus:@"评论成功"];
        [SVProgressHUD showWithStatus:@"评论成功" duration:2.0f transform:CGAffineTransformMakeRotation(M_PI)];
        [self dismissViewControllerAnimated:YES completion:nil];
      
        return;
    }
    // 官方用户。
    NSDictionary *dic = [LPCommonTool readUserDefaultObjectForKey:DSUSERKEY];
    [LPRequestParser postSaveOwnpaperAppUname:[NSString stringWithFormat:@"%@",[LPCommonTool readphoneNumber]] url:SaveOwnpaperApp SecurityCode:dic[@"password"] Point_time:self.pointTimeString MenuId:self.menuId S_menu_id:self.s_MenuId Menu_content:self.contentString block:^(id responseObject, NSError *error) {
        if (responseObject) {
            if ([responseObject[@"status"] isEqualToString:@"success"]) {
               // [SVProgressHUD showSuccessWithStatus:@"评论成功"];
                [SVProgressHUD showWithStatus:@"评论成功" duration:2.0f transform:CGAffineTransformMakeRotation(M_PI)];
                [self dismissViewControllerAnimated:YES completion:nil];
                
            }else{
                [SVProgressHUD showWithStatus:@"评论失败" duration:3.0f transform:CGAffineTransformMakeRotation(M_PI)];
            }
        }else{
            [SVProgressHUD showWithStatus:@"评论失败" duration:3.0f transform:CGAffineTransformMakeRotation(M_PI)];
        }
    }];
}


-(void)backButtonClicked{
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
